﻿using YunShop_WebAPI.BLL;
using YunShop_WebAPI.Model;
using System.Collections;
using System.Web;
using System.Web.Http;

namespace YunShop_WebAPI.API.Controllers
{
    /// <summary>
    /// 可视化数据大屏
    /// </summary>
    public class VisualizationController : ApiController
    {
        /// <summary>
        /// 门店拿货显示
        /// </summary>    
        [HttpPost,HttpGet]
        [ActionName("GetDataByRequire")]
        public Result_Model GetDataByRequire()
        {
            string mydata = CommonFun.ConvertToString(HttpContext.Current.Request.Headers["Token"]);
            int pageIndex = CommonFun.ConvertToInt(HttpContext.Current.Request["pageIndex"]) - 1;
            int pageSize = CommonFun.ConvertToInt(HttpContext.Current.Request["pageSize"]);            
            int count = 0;
            ArrayList json = SetResultList(VisualizationService.GetDataByRequire(mydata, pageIndex, pageSize), ref count);
            return new Result_Model(1, "获取成功", json, count);
        }

        /// <summary>
        /// 门店营业排名
        /// </summary>
        /// <param name="mydata"></param>
        /// <returns></returns>
        [HttpPost, HttpGet]
        [ActionName("GetDataByStock")] 
        public Result_Model GetDataByStock()
        {
            string mydata = CommonFun.ConvertToString(HttpContext.Current.Request.Headers["Token"]);
            int pageIndex = CommonFun.ConvertToInt(HttpContext.Current.Request["pageIndex"]) - 1;
            int pageSize = CommonFun.ConvertToInt(HttpContext.Current.Request["pageSize"]);

            int count = 0;
            ArrayList json = SetResultList(VisualizationService.GetDataByStock(mydata, pageIndex, pageSize), ref count);
            return new Result_Model(1, "获取成功", json, count);
        }

        /// <summary>
        /// 6个月营业情况
        /// </summary>
        /// <param name="mydata"></param>
        /// <returns></returns>    
        [HttpPost, HttpGet]
        [ActionName("GetDataByMonth")]
        public Result_Model GetDataByMonth()
        {
            string mydata = CommonFun.ConvertToString(HttpContext.Current.Request.Headers["Token"]);

            int count = 0;
            ArrayList json = SetResultList(VisualizationService.GetDataByMonth(mydata), ref count);
            return new Result_Model(1, "获取成功", json, count);
        }

        /// <summary>
        /// 门店销售分析
        /// </summary>
        /// <param name="mydata"></param>
        /// <returns></returns>  
        [HttpPost, HttpGet]
        [ActionName("GetStockAnalysis")]
        public Result_Model GetStockAnalysis()
        {
            string mydata = CommonFun.ConvertToString(HttpContext.Current.Request.Headers["Token"]);

            int count = 0;
            ArrayList json = SetResultList(VisualizationService.GetStockAnalysis(mydata), ref count);
            return new Result_Model(1, "获取成功", json, count);
        }

        /// <summary>
        /// 门店地图
        /// </summary>
        /// <param name="mydata"></param>
        /// <returns></returns>     
        [HttpPost, HttpGet]
        [ActionName("GetMapByStock")]
        public Result_Model GetMapByStock()
        {
            string mydata = CommonFun.ConvertToString(HttpContext.Current.Request.Headers["Token"]);
            int count = 0;
            ArrayList json = SetResultList(VisualizationService.GetMapByStock(mydata), ref count);
            return new Result_Model(1, "获取成功", json, count);
        }

        public ArrayList SetResultList(ArrayList json, ref int count) {
            if (json.Count > 0)
            {
                Hashtable ht = json[0] as Hashtable;
                count = CommonFun.ConvertToInt(ht["FRowCount"]);
            }
            return json;
        }
    }
}